<?php
$CI =& get_instance();

$CI->load->database();
$CI->load->library("front/header_lib");

$page_title =  "kypris guide Registration form information";

     $title = $page_title;
//	$metakey_page = $row_vals->staticpage_metakey;
  //  $metadesc_page = $row_vals->staticpage_metadesc;

$datas = array();

$CI->header_lib->display_header_element(array("script"=>array("jquery-1.4.2"),"page_title"=>$title,"metakey_page"=>$metakey_page,"metadesc_page"=>$metadesc_page));
$CI->header_lib->display_header($datas);


?>
<style>
label.error {
    margin: 2px 0px;
    width : 360px;
}
</style>
<script type="text/javascript" src="<?php echo base_url()?>js/jquery.validate.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	var result_email = true;
	$.validator.addMethod("emailCheck", function(val, elem) {                                                
        $.post("<?php echo site_url('json_request/check_directory_email')?>" ,{
             email: $('#email').val()                                  
        },function(data){
            result_email = (data=="TRUE") ? true : false;
        }, "json");
        return result_email;
    });
    
    $("#registerform").validate({
    	onkeyup: false,                 
        rules: {            
            email: {                
                required : true,                
                email : true,
                emailCheck: true            
            },
            name: {         
                required: true            
            },
            
            telephone: {                
                required: true,
                digits:true
            }                        
                    
        },        
        messages: {           
            email: {                
                required : "Please input your e-mail address",                
                email : "Please input a valid e-mail address",
                emailCheck : "The e-mail address already exists in the database"            
            },
           name: {            
                required: "Please input your name"            
            },
           
            telephone: {                
               required: "Please input  telephone",
               digits: "Please input  valid telephone"
            }
        }          
      });
});
</script>
<!--body content starts-->

<div id="container_wrapper">
	
    	<div class="left_part">

             <?php $this->load->view(TEMPLATE_NAME.'/front/login_left'); ?>   

        </div>

        <div class="right_part">
            testing payment system
            <?php
            if ( !defined( 'SMARTY_DIR' ) ) {
	include_once( 'init.php' );
}

// make sure post if from ccbill server
if(   $_SERVER['REMOTE_ADDR'] != '64.38.240.97' ) 
              {exit;}
/*							
ob_start();
				foreach($_POST as $k => $v )
			   	print " $k = $v \n";
				
				print "\n\n---------------------------\n".$_SERVER['REMOTE_ADDR'];
				$s =ob_get_contents();
				ob_end_clean();
				
$fo = fopen("ccbill.txt","w+");
      fwrite($fo,$s);
			fclose($fo);  
*/			

//already processed subscription_id, exit
$trnrec=$db->getRow('select * from ! where txn_id = ? ', array(TRANSACTIONS_TABLE, $_POST['subscription_id'] ));
if( $trnrec['id'] )
 exit;
 
 
// amount paid is less than amount expected 
$trnrec=$db->getRow('select * from ! where invoice_no = ? ', array(TRANSACTIONS_TABLE, $_POST['invoiceid'] ));
if( $_POST['initialPrice']   < $trnrec['amount_paid']   )
  { 
	
	
	$params['payment_status'] = 'Error'; 
	
	
	}
	else {

  if (  isset($_POST['subscription_id']) && strlen($_POST['subscription_id']) >  3 ) {
	  $params['payment_status'] = 'Completed';
  } elseif (  isset($_POST['reasonForDecline'])  ) {
	  $params['payment_status'] = 'Declined';
  } else {$params['payment_status'] = 'Error'; }

}

$params['txn_id'] = $_POST['subscription_id'];
$params['valid'] = true;
$params['pay_txn_id'] = $_POST['invoiceid'];
$params['paid_thru'] = 'ccbill';
$params['amount'] = $_POST['initialPrice'];
$params['email'] = $_POST['email'];
$params['vars']  = serialize($_POST);
print_r($params);
//$level_name = process_payment_info($params); 
echo '<pre>';
print_r($_POST);
echo '</pre>'; 




?>
<form action='https://bill.ccbill.com/jpost/signup.cgi'  method=POST>

<input  type=hidden name=clientAccnum  value='942799'>

<input  type=hidden name=clientSubacc  value='0000'>

<input type=hidden  name=formName  value='144cc'>

<input type=hidden name=VariableName value="name1">

<input type=hidden name=VariableName2 value="name2">

<input type=submit name=submit  value='Join  Now'>

</form>
        </div>
             <?php $this->load->view(TEMPLATE_NAME.'/front/side_right'); ?>  
        <div class="clear"></div>
    </div>

<!--body content ends-->

        <div class="clear"></div>


<!--body content ends-->
<?php
$CI->load->library("front/footer_lib");
$CI->footer_lib->display_footer();
?>

<?php
$CI->footer_lib->display_footer_element();

?>